package org.hwadee.service;

import org.hwadee.entity.Communication;
import org.hwadee.mapper.CommunicationMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CommunicationService {

    @Autowired
    private UserService userService;

    @Autowired
    private CommunicationMapper communicationMapper;


    public List<Communication> listCommunicationByTime(Integer userId) {
        List<Communication> communications = communicationMapper.listCommunicationByTime(userId);
        for(Communication communication : communications) {
            communication.setSenderUser(userService.getUserById(communication.getSender()));
            communication.setReceiverUser(userService.getUserById(communication.getReceiver()));
        }
        return communications;
    }

    public Communication selectCommunicationBySenderAndReceiverId(Integer senderId, Integer receiverId) {
        return communicationMapper.selectCommunicationBySenderAndReceiverId(senderId,receiverId);
    }

    public void insertCommunication(Communication communication) {
        communicationMapper.insertCommunication(communication);
    }
}
